from PyQt5.Qt import *
import sys



class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("堆叠布局")
        self.resize(600,400)
        sl = QStackedLayout()
        self.setLayout(sl)

        lb1 = QLabel('标签1')
        lb1.setStyleSheet('''
               background-color:red;
               ''')
        lb2 = QLabel('标签2')
        lb2.setStyleSheet('''
                    background-color:green;
                    ''')
        lb3 = QLabel('标签3')
        lb3.setStyleSheet('''
                    background-color:blue;
                    ''')

        sl.addWidget(lb1)
        sl.addWidget(lb2)
        sl.addWidget(lb3)
        # sl.setCurrentIndex(2) # 切换叠层
        # sl.setCurrentWidget(lb1)

        sl.setStackingMode(QStackedLayout.StackAll)
        lb1.setFixedSize(200,200)
        lb2.setFixedSize(300, 300)




if __name__=='__main__':
    app = QApplication(sys.argv)
    w = Window()
    w.show()
    sys.exit(app.exec_())